package com.hoopchina.util;

import java.util.Calendar;

public class TimeUtils {
	/**
	 * 时间格式转化
	 * @param updateTime
	 * @return
	 */
	public static String getUpdateTime(String updateTime){
		String result="";
		try {
			long currentTimeSec= System.currentTimeMillis()/1000;
			long calTime=Long.parseLong(updateTime);
			long timeDif=currentTimeSec-calTime;
			if (timeDif<60)
			{
				result="刚刚";
			}else if(timeDif<60*60) {
				result=(timeDif/60)+"分钟前";
			}else if (timeDif<60*60*24) {
				result=timeDif/3600+"小时前";
			}else {
				result=getDate(calTime);
			}
		} catch (Exception e) {
			result="格式错误";
		}
		
       return result;	
	}
	/**
	 * 格式转化：yy-MM-dd
	 * @param timeSec
	 * @return
	 */
	public static String getDate(Long timeSec) {
		StringBuilder sb=new StringBuilder();
		Long time=timeSec*1000;
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(time);
		sb.append(cal.get(Calendar.YEAR)).append("-");
		sb.append(cal.get(Calendar.MONTH)+1).append("-");
		sb.append(cal.get(Calendar.DATE));
		return sb.toString();
	}
	/**
	 * 格式转化：yy-MM-dd hh：mm：ss
	 * @param timeSec 网络传输回来的时间（秒）
	 * @return 详细时间
	 */
	public static String getDetailDate(String timeSec){
		try {
			Long time=Long.parseLong(timeSec)*1000;
			Calendar cal = Calendar.getInstance();
			cal.setTimeInMillis(time);
			StringBuilder sb=new StringBuilder();
			sb.append(cal.get(Calendar.YEAR)).append("-");
			sb.append(cal.get(Calendar.MONTH)+1).append("-");
			sb.append(cal.get(Calendar.DATE)).append(" ");
			sb.append(cal.get(Calendar.HOUR_OF_DAY)).append(":");
			sb.append(cal.get(Calendar.MINUTE)).append(":");
			sb.append(cal.get(Calendar.SECOND));
			return sb.toString();
		} catch (Exception e) {
			return "时间传输有误";
		}
		
		
	}
	
	
   /* public static String formatTime( String aSeconds ) {
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
        Date date = new Date();
        long seconds = Long.parseLong( aSeconds );
        date.setTime( seconds * 1000 );
        String formatDate = sdf.format( date );

        return formatDate;        
    }
    
    public static int getYear( String aSeconds ) {
        Date date = new Date();
        long seconds = Long.parseLong( aSeconds );
        date.setTime( seconds * 1000 );
        
        int year = date.getYear() + 1900;

        return year;  
    }
    
    public static int getMonth( String aSeconds ) {
        Date date = new Date();
        long seconds = Long.parseLong( aSeconds );
        date.setTime( seconds * 1000 );
        
        int month = date.getMonth() + 1;
        
        return month;  
    }
    
    public static int getDate( String aSeconds ) {
        Date date = new Date();
        long seconds = Long.parseLong( aSeconds );
        date.setTime( seconds * 1000 );
        
        return date.getDate();          
    }
    
    public static int getHour( String aSeconds ) {
        Date date = new Date();
        long seconds = Long.parseLong( aSeconds );
        date.setTime( seconds * 1000 );
        
        return date.getHours();          
    }
    
    public static int getMinute( String aSeconds ) {
        Date date = new Date();
        long seconds = Long.parseLong( aSeconds );
        date.setTime( seconds * 1000 );
        
        return date.getMinutes();          
    }
    
    public static int getSecond( String aSeconds ) {
        Date date = new Date();
        long seconds = Long.parseLong( aSeconds );
        date.setTime( seconds * 1000 );
        
        return date.getSeconds();   
    }*/

}
